{% extends 'main.html' %}
{% load func %}

{% block title %}
    <title>asset info</title>
{% endblock %}


{% block content %}
<div class="panel-body" id="asset_page">
<center><h4 style="color: red" id="error"></h4></center>
    <div class="pad-btm form-inline">
        <div class="row">
            <div class="col-sm-6 table-toolbar-left">
                 <button id="demo-bootbox-custom-h-form" class="btn btn-warning" onclick="return allow_asset()">设为合法</button>
            </div>
            <div class="col-sm-6 table-toolbar-right">

                <div class="btn-group">
                    <div class="btn-group dropdown">

                       <div class="form-group">
                             <input id="search" type="text" placeholder="请输入ip" class="form-control" autocomplete="off">
                             <button id="demo-btn-addrow" class="btn btn-purple" onclick="search()"> 搜索</button>
                             <a href="/discard_asset/"><button id="demo-btn-addrow" class="btn btn-purple"><i class="demo-pli-add"></i> 显示所有</button></a>

                       </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>操作</th>
                    <th>主机名</th>
                    <th>序列号</th>
                    <th>管理地址</th>
                    <th>制造商</th>
                    <th>型号</th>
                    <th>操作系统</th>
                    <th>汇报时间</th>
                </tr>
            </thead>
            <tbody>
                {% for server in all_asset %}
                    <tr>
                        <td><input type="checkbox" value="{{ server.id }}"></td>
                        <td>{{ server.hostname }}</td>
                        <td>{{ server.sn }}</td>
                        <td>{{ server.manage_ipv4 }}</td>
                        <td><span class="text-muted"><i class="demo-pli-clock"></i> {{ server.manufacturer }}</span></td>
                        <td>{{ server.model }}</td>
                        <td><i class="demo-pli-mine"></i> {{ server.os_platform }}</td>
                        <td><i class="demo-pli-mine"></i> {{ server.create_at }}</td>

                    </tr>
                {% endfor %}

            </tbody>
        </table>
        <div class="pull-right">
            <ul class="pagination text-nowrap mar-no">
                {% page all_asset 'discard_asset' %}
            </ul>
        </div>

    </div>
</div>

<div class="panel-body" id="save_asset" style="display: none;">
<div class="panel">
    <div class="panel-heading">
        <h3 class="panel-title">新资产入库</h3>
    </div>
    <form class="form-horizontal" method="POST">
        <div class="panel-body">
            {% for row in obj %}
            <div class="form-group">
                <label class="col-sm-3 control-label" for="demo-is-inputsmall">{{ row.label }}</label>
                <div class="col-sm-6">
                  {{ row }}
                </div>
            </div>
            {% endfor %}
            </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-9 col-sm-offset-3">
                    <button class="btn btn-mint" type="submit" onclick="save()">保存</button>
                    <button class="btn btn-warning" type="reset">重填</button>
                    <button class="btn btn-danger" onclick="save()">取消</button>
                </div>
            </div>
        </div>
    </form>
</div>
</div>
<script>
    function allow_asset(){
        var choicesed_asset_count=$('input:checked').length;
        if(choicesed_asset_count <1){
            $('#error').text('你必须选择一条资产');
            return false
        }

        if(confirm('设为合法后客户端将可以继续向服务端汇报资产信息！！请确认客户端是为恶意汇报！！')){
            console.log('allow asset')
        }
        else {
            return false
        }

        $.ajax({
            url:'/discard_asset/',
            type:'DELETE',
            data:{'server_id':$('input:checked').attr('value')},
            success:function(arg){
                location.reload()
            }
        })
    }
    function search(){
        var ip=$('#search').val();
        if (ip.length == 0){
            $('#error').text('必须输入一个ip地址');
            return false
        }
        location.href='/discard_asset/?ip='+ip
    }
    function go(){
        var page_num=$('#go').val();
        location.href="/discard_asset/?page="+page_num;
    }
</script>
{% endblock %}
